package com.lpinfo.spb.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lpinfo.spb.LpinfoSpbApplicationTests;
import com.lpinfo.spb.plateform.system.dto.SysUserDto;
import com.lpinfo.spb.plateform.system.entity.SysUser;
import com.lpinfo.spb.plateform.system.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Slf4j
@Transactional
@Rollback(true)
@Component
public class SysUserServiceSuit extends LpinfoSpbApplicationTests {

    @Autowired
    private SysUserService service;

    @Test
    public void testSuitCase() {
        Long primaryKey=System.currentTimeMillis();
////////////////新增
        SysUser insertEntity  = new SysUser();
        insertEntity.setUserId(primaryKey);
        insertEntity.setUserName("zhangsan");
        insertEntity.setUserPassword("123456");
        insertEntity.setNickName("张三");
        //1:男 2:女
        insertEntity.setUserGender("1");
        insertEntity.setUserPhone("18800001111");
        insertEntity.setUserAvatar("http://lpinfo.top/upload/zhangsan.png");
        insertEntity.setDeptId(1L);
        //1:正常 2:已锁定
        insertEntity.setLockedFlag("1");
        //1:正常 2:已删除
        insertEntity.setDeleteFlag("1");
        insertEntity.setTenantId(1L);
        //创建人存ID
        insertEntity.setCreateUser(1L);
        insertEntity.setCreateTime(LocalDateTime.now());
        Boolean insertResult =  service.save(insertEntity);
        Assert.assertEquals(true,insertResult);
        log.info("====insertResult"+insertResult);
////////////////修改
        SysUser updateEntity  = new SysUser();
            updateEntity.setUserId(primaryKey);
            updateEntity.setNickName("张三疯");
        Boolean updateResult =  service.updateById(updateEntity);
        Assert.assertEquals(true,updateResult);
        log.info("====updateResult"+updateResult);
///////////////查询
        SysUser selectResult =  service.getById(primaryKey);
        Assert.assertEquals("张三疯",selectResult.getNickName());
        log.info("====updateResult:{}",selectResult);
/////////////分页列表
        SysUserDto pageEntity  = new SysUserDto();
        pageEntity.setUserPhone("18800001111");
        Page<SysUser> page = new Page<SysUser>(1,10);
        IPage<SysUser> pageList =  service.page(page,pageEntity);
        Assert.assertNotNull(pageList);
        log.info("====pageList:{}",pageList);
///////////根据用户名查询用户信息
        SysUser getUserByUserNameResult = service.selectUserByUserName("zhangsan");
        Assert.assertEquals("张三疯",getUserByUserNameResult.getNickName());
        log.info("====getUserByUserNameResult:{}",getUserByUserNameResult);
/////////////删除
        Boolean deleteResult =  service.removeById(primaryKey);
        Assert.assertEquals(true,deleteResult);
        log.info("====deleteResult:"+deleteResult);
    }

}
